//
//  NSDate+GDate.m
//  KingDraw
//
//  Created by Mask on 2018/5/16.
//  Copyright © 2018年 Mask. All rights reserved.
//

#import "NSDate+GDate.h"

@implementation NSDate (GDate)

+ (NSString *)transformDateToFormatterStr:(NSDate *)date andFormatter:(NSString *)format{
    NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
    [formatter setDateFormat:format];
    [formatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT+0800"]];
    return [formatter stringFromDate:date]? [formatter stringFromDate:date]:@"";
}



+ (NSTimeInterval)returnNowDateTimeInterval{
    double timeIn=[NSDate date].timeIntervalSince1970*1000;
    return timeIn;
}

+ (NSString *)interceptDateWith:(NSString *)str{
    NSArray *array=[str componentsSeparatedByString:@"("];
    NSArray *brray=[[array objectAtIndex:1] componentsSeparatedByString:@")"];
    return [brray objectAtIndex:0];
}

//时间转换
+ (NSString *)transformLongStrToDateStr:(NSString *)longStr format:(NSString *)format andTimeZone:(NSString *)timeZone{
    if (longStr == nil || longStr.length <= 0) {
        return @"";
    }
    NSRange range=[longStr rangeOfString:@"("];
    NSString *str=longStr;
    if (range.location!=NSNotFound) {
        str=[NSDate interceptDateWith:longStr];
    }
    NSDate *theDay=[NSDate dateWithTimeIntervalSince1970:[str doubleValue]/1000];
    NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
    [formatter setDateFormat:format];
    [formatter setTimeZone:[NSTimeZone timeZoneWithName:timeZone]];
    NSString *dateStr=[formatter stringFromDate:theDay];
    return dateStr;
}



@end
